import { defineStore } from 'pinia'
import * as api from '@/api/param'

export const paramStore = defineStore('param', {
  state: () => ({
    //参数列表
    paramList: [],
    pagination: {
        page: 1,
        limit: 6,
        total: 0,
      },
  }),
  actions: {
    // 获取参数列表-带分页
    async getParamPage(param) {
      try {
        const params = {
           ...param,
            page: this.pagination.page,
            limit: this.pagination.limit
        } 
        // console.log('params', params)
        const res = await api.getParamPage(params)  
        this.paramList = res.list || []
        this.pagination.total = res.total
        // return res
      } catch(error) {
        throw error
      }
    },

    // 获取参数详情
    async getParamInfo(id) {
      try {
        const res = await api.getParam(id)
        // console.log('res', res)
        return res
      } catch(error) {
        throw error
      }
    },

    async saveParam(dataForm) {
        await api.saveParam(dataForm)
    },
    // 新增参数
    /*async addParam(dataForm) {
      try {
        const res = await api.addParam(dataForm)
        return res
      } catch(error) {
        throw error
      }
    },*/

    // 编辑参数
    /*async editParam(dataForm) {
      try {
        const res = await api.editParam(dataForm)
        return res
      } catch(error) {
        throw error
      }
    },*/

    // 删除参数
    async deleteParam(ids) {
      try {
        const res = await api.deleteParam(ids)
        return res
      } catch(error) {
        throw error
      }
    }
  }
})
